package top.jlzhou;

import java.util.Properties;

import top.jlzhou.tools.HttpService;

/**
 * <pre>
 * 工具类入口
 * ClassName : top.jlzhou.T
 * Author : J.L.Zhou
 * Date : 2019年3月12日 上午10:33:23
 * Version : V1.0
 * Copyright 2019 jlzhou.top Inc. All rights reserved. 
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目</pre>
 */
public class T extends top.jlzhou.tools.T {

	private static T instance;
	
	public T(HttpService http, long centerId, long workerId) {
		super(http, centerId, workerId);
		T.instance = this;
	}


	/**
	 * 使用默认配置新建一个工具实例子 newInstance
	 * 
	 * @return
	 * @throws CodeException:
	 */

	public static T getInstance() {
		if (instance == null) {
			Properties config = new Properties();
			long centerId = 0L;
			long workerId = 0L;
			HttpService http = null;
			String cls1 = "top.jlzhou.tools.http.HttpServiceByHttpClientImpl";
			try {
				config.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/tools.properties"));
				centerId = Long.valueOf(config.getProperty("tools.id.centerId"));
				workerId = Long.valueOf(config.getProperty("tools.id.workerId"));
				cls1 = config.getProperty("tools.HttpUtil");
				try {
					http = (HttpService) Class.forName(cls1).newInstance();
				} catch (Throwable e) {
					System.err.println("HttpService不可用：" + e.getMessage());
				}
			} catch (Exception ex) {
			}
			new T(http, centerId, workerId);
		}

		return instance;
	}
}
